import time
from multiprocessing import Process, Queue
import os

# 初始化队列，队列长度最大为3个元素
q = Queue(3)
q.put('进程')
q.put('线程')
q.put('协程')
# q.put('test')
print(q.full(), q.qsize())
print(q.get(), q.get(), q.get())
# q.get()
print(q.empty())
print(os.getpid(), os.getppid())

list1 = ['芒果', '苹果', '香蕉']


def wdata(q):
    for i in list1:
        print(f'将水果{i}放入队列')
        q.put(i)
        time.sleep(0.2)


def rdata(q):
    while True:
        if q.empty():
            break
        else:
            print(f'从队列取出水果{q.get()}')


if __name__ == '__main__':
    q1 = Queue()
    p1 = Process(target=wdata, args=(q1,))
    p2 = Process(target=rdata, args=(q1,))
    p1.start()
    print('p1的pid', p1.pid)
    p1.join()
    p2.start()
    print('p2的pid', p2.pid)
    p2.join()
